package com.hlf.modules.api.controller;

import com.hlf.common.constants.Constants;
import com.hlf.common.utils.ReturnResult;
import com.hlf.common.validator.Assert;
import com.hlf.modules.api.annotation.AuthIgnore;
import com.hlf.modules.api.annotation.LoginUser;
import com.hlf.modules.api.entity.BusinessKind;
import com.hlf.modules.api.service.SMSService;
import com.hlf.modules.sys.entity.SysUserEntity;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 公共接口
 */


@RestController
@RequestMapping("/api/common")
@Api("公共接口")
public class ApiCommonController {
    @Autowired
    private SMSService sMSService;

    /**
     * 发送验证码
     * @param mobile
     * @return
     */
    @AuthIgnore
    @ApiOperation(value = "发送验证码",notes = "发送验证码")
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "query", dataType="string", name = "mobile", value = "手机号", required = true),
            @ApiImplicitParam(paramType = "query", dataType="string", name = "codeType", value = "类型- 0=注册，1=密码找回", required = true)
    })
    @PostMapping("/sendCode")
    public ReturnResult sendCode(String mobile , String codeType) {
        Assert.isBlank(mobile, "手机号不能为空");
        Assert.isBlank(codeType, "类型不能为空");
        sMSService.sendMoblieVCode(mobile,Integer.parseInt(codeType),1);
        return ReturnResult.ok();
    }

    /**
     * 给商家发送验证码
     * @param
     * @return
     */
    @ApiOperation(value = "给商家发送验证码",notes = "给商家发送验证码")
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "query", dataType = "string", name = "token", value = "token", required = true)
    })
    @GetMapping("/merchantCode")
    public ReturnResult sendMerchantCode(@LoginUser SysUserEntity user) {
        sMSService.sendMoblieVCode(user.getMobile(), Constants.MESSAGE_TYPE_OTHER,1);
        return ReturnResult.ok();
    }

    /**
     * 获取主营类目
     */
    @AuthIgnore
    @ApiOperation(value = "获取主营类目",notes = "获取主营类目")
    @GetMapping("/getKind")
    public ReturnResult getKind() {
        List<BusinessKind> businessKinds = sMSService.getKind();
        return ReturnResult.ok().put(Constants.DEFAULT_RESULT_NAME,businessKinds);
    }

}
